import { FormSchema } from '/@/components/Table';

export const logicalConditions = [
  {
    label: '或(只需有一个条件成立)',
    value: 1,
  },
  {
    label: '且(只有当前步骤触发的条件成立)',
    value: 2,
  },
];
export const activityFNTypeList = [
  {
    value: 0,
    label: '全部人员已完成',
  },
  {
    value: 1,
    label: '至少一人已完成',
  },
  {
    value: 2,
    label: '完成人数',
  },
  {
    value: 3,
    label: '完成百分比',
  },
  {
    value: 4,
    label: '未完成人数',
  },
  {
    value: 5,
    label: '未完成百分比',
  },
];

export const compareTypeOptions = [
  {
    label: '等于(=)',
    value: 0,
  },
  {
    label: '大于(>)',
    value: 1,
  },
  {
    label: '大于等于(>=)',
    value: 2,
  },
  {
    label: '小于(<)',
    value: 3,
  },
  {
    label: '小于等于(<=)',
    value: 4,
  },
  {
    label: '不等于 (<>)',
    value: 5,
  },
];
export const conditionItemDefault = {
  conditionName: '新条件',
  conditionType: null,
  children: [] as any,
  activityFNType: null,
  responseChoice: null,
  compareType: null,
  compareContent: '',
  tumTrfType: 0,
  sourceActivityId: null,
  bindPropName: null,
};
export const conditionItemBase = {
  conditionName: '或(只需有一个条件成立)',
  conditionId: 1,
  key: 1,
  conditionType: 1,
  children: [] as any,
  activityFNType: null,
  responseChoice: null,
  compareType: null,
  compareContent: '',
  tumTrfType: 0,
  sourceActivityId: null,
  bindPropName: null,
};

export const stepFormSchema: FormSchema[] = [
  {
    field: 'sourceActivityId',
    label: '步骤名称',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
  },
  {
    field: 'activityFNType',
    label: '处理类型',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
    componentProps: ({ formModel }) => {
      return {
        options: activityFNTypeList,

        onChange: () => {
          formModel.compareContent = '';
          formModel.compareType = null;
        },
      };
    },
  },
  {
    field: 'responseChoice',
    label: '处理意见',
    component: 'Select',
    componentProps: {
      placeholder: '请选择处理意见',
    },
    colProps: { span: 24 },
  },
  {
    field: 'compareType',
    label: '完成情况',
    component: 'Select',
    colProps: { span: 24 },
    dynamicDisabled: ({ values }) => {
      if (values.activityFNType && values.activityFNType !== 0 && values.activityFNType !== 1) {
        return false;
      } else {
        return true;
      }
    },
    componentProps: {
      options: compareTypeOptions,
    },
  },
  {
    field: 'compareContent',
    label: '完成内容',
    component: 'InputNumber',
    colProps: { span: 16 },
    dynamicDisabled: ({ values }) => {
      if (
        values.activityFNType &&
        values.activityFNType?.value !== 0 &&
        values.activityFNType?.value !== 1
      ) {
        return false;
      } else {
        return true;
      }
    },
    suffix: (value) => {
      if (value.model.activityFNType) {
        if (value.model.activityFNType?.value === 2 || value.model.activityFNType?.value === 4) {
          return '人';
        } else if (
          value.model.activityFNType?.value === 3 ||
          value.model.activityFNType?.value === 5
        ) {
          return '%';
        } else {
          return '';
        }
      } else {
        return '';
      }
    },
  },
];

export const logicFormSchema: FormSchema[] = [
  {
    field: 'conditionType',
    label: '逻辑条件',
    required: true,
    component: 'RadioGroup',
    colProps: { span: 24 },
    componentProps: {
      options: [
        {
          label: '或',
          value: 1,
        },
        {
          label: '且',
          value: 2,
        },
      ],
    },
  },
];

export const controlFormSchema: FormSchema[] = [
  {
    field: 'bindPropName',
    label: '属性名称',
    component: 'Select',
    required: true,
    colProps: { span: 24 },
  },
  {
    field: 'compareType',
    label: '比较情况',
    required: true,
    component: 'Select',
    colProps: { span: 24 },
    componentProps: {
      options: compareTypeOptions,
    },
  },
  {
    field: 'compareContent',
    required: true,
    label: '比较值',
    component: 'Input',
    colProps: { span: 24 },
  },
];

export const levelList = ['#4DB803', '#FC7C22', '#FF522B'];
